package com.jeremyaburns.oddio 
{
	public class TrackNote extends TrackItem
	{
		public var pitch    :int;
		public var duration :int;
		
		private var mSamplesPerWave :int;
		public function get samplesPerWave() :int { return mSamplesPerWave; }
		
		private var mEndIndexInSamples :int 
		public function get endIndexInSamples() :int { return mEndIndexInSamples; }
		
		public function TrackNote( timeIndex:int=0, pitch:int=0, duration:int=1 )
		{
			super( timeIndex );
			this.pitch    = pitch;
			this.duration = duration;
		}
		
		override public function prepareForPlayback( tempo:int ):void 
		{
			super.prepareForPlayback( tempo );
			mSamplesPerWave = getSamplesPerWaveFromPitch( pitch );
			mEndIndexInSamples = timeIndexInSamples + duration*tempo;
		}
		
		
		static public function getSamplesPerWaveFromPitch( pitch:int ) :int {
			return int( 44100 / (440*Math.pow(2,(pitch-57)/12)) );
		}
	}
}